package drg_group.beijing_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.beijing_2022.Base;
import drg_group.beijing_2022.MedicalRecord;
import drg_group.beijing_2022.ADRG.*;

public class MDCE{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"J14.x00","J10.100x005","R91.x00x001","J98.700","R94.200","J95.800x021","J45.901","J20.000","J15.600x002","J84.000x003","J86.004","A15.006","A19.000x020","J84.100x008","C34.000","J62.800x002","A15.207","B37.800x083","A22.102+J17.0*","A15.901","D15.900","S27.600","T17.900","R06.100","J39.807","R94.201","C46.701","J98.800x003","A15.100x007","J63.800x014","A15.304","B37.803","A16.202","E85.407","J18.800x004","J95.804","J96.900x003","J80.x01","J98.901","I89.800x018","Q33.301","A15.500x003","A19.000x015","D38.104","A19.000x010","D02.100","I89.000x027","A19.000x008","J84.100x007","J62.804","J45.900x013","J61.x00x003","J98.010","Q33.200","M05.101+J99.0*","J45.900x023","T17.802","I88.107","J70.900","D17.400x003","D18.000x857","A16.104","A15.100x001","E89.802","U07.000","A15.100x003","B40.100","J84.108","J98.005","A19.000x018","A16.021","A19.000x014","J18.900","A16.000x002","J98.007","J62.800x003","J62.800x005","J63.803","E83.104+J99.8*","J98.500x007","A19.000x007","J90.x00x002","J94.901","A15.801","J96.900x001","C49.302","J98.800x009","C34.000x003","J13.x00","A16.100x001","D02.201","J41.100","A15.500x029","I26.900x011","C78.306","R04.900","T17.400","C34.900x008","J84.803","J15.600x006","J98.002","J67.300","J86.016","J98.500x008","A16.900x002","A37.901+J17.0*","C77.103","A16.200x015","B01.200+J17.1*","A19.803","I89.800x023","D17.700x023","J44.100","Q33.600","R91.x03","J98.418","A15.808","J98.100","J39.810","J70.101","A37.000","C34.900x004","J68.000x001","J68.800","R06.803","R09.800x091","J09.x02","J44.805","A15.400x001","S27.010","A16.005","J95.800x004","J98.101","Q32.200","J20.200","S27.100","J20.900","J15.600x005","J47.x03","D14.400","J61.x00x001","A16.010","J63.201","J90.x00x004","I26.901","J98.410","A15.102","J94.800x010","R04.800x004","D86.000","A16.011","J20.800","J67.400","S27.610","A15.003","A15.500x018","A16.028","C34.801","J45.002","Q33.000","Z03.800x001","A16.019","J21.901","A16.009","B65.907+I52.1*","R09.101","C34.902","A16.002","C45.700","A19.000x003","A37.100","A16.806","J84.001","J15.903","J68.900","E85.400x005","A16.400x010","J94.806","J98.404","J98.008","T17.801","J98.415","A15.401","C34.802","A15.500x022","J63.800x023","J69.001","I26.900x015","I26.900x016","J70.800","J98.009","S27.000","R09.100","D17.700x019","J98.400x008","A15.000x012","B77.801+J17.3*","J68.002","C79.807","E32.800x004","J18.100","D17.400x002","J42.x01","J45.000x003","J10.000","A15.000x010","D36.700x008","J96.000","J98.416","J67.600","E84.001","A16.027","J98.500x001","R84.200","C34.100x003","J93.900","A15.007","J15.000","A37.900","J20.902","B48.502+J17.2*","J84.102","D38.100x003","J16.000","B37.101+J17.2*","Q79.000","R84.400","A16.033","J98.601","D38.102","B44.000x001+J99.8*","I89.800x007","J63.100","J46.x00x008","J63.000","M31.302+J99.1*","J60.x00x005","A16.106","R59.009","A15.501","J85.300","J12.200","E32.000","J15.800x002","J67.700x002","A15.800x001","J44.801","J62.001","J82.x00x005","R04.800x002","C45.701","A16.108","J66.000","J90.x02","J98.400x019","B39.100x001+J17.2*","D02.200x002","J18.200","J39.808","I26.900x013","A16.109","J44.000","A16.031","C79.800x838","A52.704+J99.8*","J86.903","A16.900x023","J15.402","J45.000x001","A15.300x001","T17.501","A19.801","J92.900x002","A15.000x002","T86.800x011","A54.806+J17.0*","A15.809","J63.200","J86.002","J18.901","A15.100x009","J67.100","J63.800x026","D02.400","J98.407","R06.400","S27.500","S27.808","J18.001","J84.800x005","A15.000x028","I89.807","J44.900x002","J94.804","R06.300","S27.811","C45.702","I89.000x016","A06.500x002+J99.8*","J86.019","I26.900x017","I28.800x010","J95.100","A15.500x028","A15.500x011","J61.x01","J84.805","J98.403","A16.206","J98.400x012","R93.805","J42.x00","A15.000x001","A15.811","C79.810","D14.200","A16.018","J69.000","J86.003","A15.609","J45.900x002","J81.x00","Q33.800x001","A16.030","A16.101","C38.800","J98.102","B38.200x001+J17.2*","J86.901","A16.200x007","J46.x00x002","J98.801","J63.802","Q32.401","D36.700x013","A15.500x010","B49.x13","I26.900x002","J44.800x001","J94.101","J67.800x003","J98.001","J98.004","J98.400x005","M33.001+J99.1*","A16.500x010","J15.902","J18.800x012","J68.001","J63.301","J67.800x001","R84.903","A19.000x005","S28.100","A15.204","U07.100x001","J63.800x022","J66.200","I26.900x001","A16.210","T17.804","S27.910","J98.405","M34.801+J99.1*","A19.000x017","J39.802","J45.005","J18.903","J93.100x002","R91.x00x005","B46.000x001+J99.8*","J15.300","A16.402","R84.904","J98.507","J46.x01","A16.026","A15.500x027","A15.900","J63.800x025","J86.006","J86.013","C77.104","A16.014","J86.015","Q79.102","J98.800x004","T27.700","J44.807","J98.200","C34.300x004","C45.000","J98.409","E32.900","J63.800x013","C38.400","S27.410","A16.207","S27.311","J98.602","Q32.400x004","A16.504","Q33.900","C78.002","J68.201","J70.001","R84.600","A15.205","D38.105","R91.x01","J63.500","A16.807","J18.800x001","A16.205","J44.900x005","Q33.003","A16.802","I89.800x016","J60.x00x004","A16.300x007","C38.300","J86.018","A16.007","J95.811","J11.000x001","J42.x00x005","J63.800x021","J98.402","S27.200","J11.100x005","A15.202","A15.604","A19.000","J12.800","J66.800","S27.900","J85.100","J86.001","B40.000","A15.805","D15.200x001","J44.900","J90.x00x005","J94.900x001","S29.900","A15.000x014","E32.802","J95.800x012","R06.000x002","J84.800x006","B38.100x001+J17.2*","J21.900","J39.803","A01.000x005+J17.0*","J12.900","B58.300+J17.3*","A15.105","J63.001","J63.800x019","J84.800x004","J98.000x013","J86.012","I89.000x029","J85.001","E32.001","J96.100","J44.900x003","S27.801","M31.300x002","J86.000x006","J42.x00x006","J60.x00x002","A16.805","C38.100","J84.802","C78.200","D38.300x003","A19.800","C34.301","J62.800x007","A16.803","A15.504","J85.002","A15.201","A15.602","B49.x00x011","I26.900x012","J85.000x002","A15.104","A19.000x006","E85.412+J99.8*","I88.900x008","I00.x00x007+J17.8*","A15.603","J95.808","I26.900x005","A15.804","J40.x00","J45.100","R05.x00","J98.000x009","R06.806","B05.200+J17.1*","D15.000","J63.800x005","A15.408","A16.000x001","A16.200x013","A16.200x014","A15.000x018","A19.802","C34.800","D15.701","A16.200x002","D38.400x001","J45.004","A15.702","R06.301","A15.306","A16.107","A16.036","A15.506","C79.800x829","I89.000x028","J92.000","A16.900x001","J44.802","B39.200x001+J17.2*","A16.300x002","J98.800x007","D38.401","I26.900x006","J18.802","D48.710","B38.000","B38.200","J98.800x016","S27.312","I26.902","B67.100x001+J99.8*","C34.102","J84.800x007","C77.100","J67.200x003","J45.100x003","A15.303","J45.900x041","J47.x00","A15.500x019","Q32.402","C77.101","T27.300","D18.100x026","A15.000x020","A16.800x002","C77.100x004","D38.100x001","J84.100x006","S27.300x012","M31.304+J99.1*","R09.200","B48.500+J17.2*","C37.x00","A15.404","B44.102+J17.2*","J98.802","J85.200","A16.008","D36.717","S29.700","J42.x00x001","J82.x00x002","J98.411","J45.800","C76.100x003","A16.503","D38.301","J82.x01","A16.400x011","D18.011","J98.501","A16.034","J43.800x001","B41.000","J67.400x002","J21.801","J45.900x011","J63.000x002","A15.409","B38.000x001+J17.2*","J63.800x017","D19.000","J95.200","J95.401","A15.500x002","J95.802","R84.300","A06.501+J99.8*","S27.210","A15.500x026","A19.000x016","A21.201+J17.0*","A15.200x001","A15.507","I26.900x007","I89.804","A15.206","J20.100","J62.800x006","J86.011","J18.800x006","J42.x00x004","B44.101+J99.8*","J63.800x009","J63.801","Q79.101","J68.400","J18.803","T17.500","S27.802","S27.302","J39.806","A19.001","J98.508","J95.800x009","J45.902","J98.503","S27.805","A15.500x021","B33.400x001+J17.1*","A16.016","C34.800x002","D14.302","J15.100","J43.901","E32.000x003","J65.x00","J20.600","J98.414","R84.000","A15.500x014","I89.003","D17.400x005","A15.002","A16.032","A15.307","Q34.000","J43.100","J63.000x003","J69.101","J94.802","S27.110","J70.300","J15.101","J18.800x002","J98.800x018","D18.100x025","J98.505","I26.900x018","A16.038","J67.800x005","J86.017","B65.902+J99.8*","J64.x00","J98.408","J90.x00x003","A37.900x003","A16.405","B38.100","J86.010","S27.812","J15.901","J94.800x004","J47.x01","C49.300x003","Q34.900","R84.700","J10.000x001","C78.304","A16.303","A16.201","A16.500x008","A15.100x005","J94.805","R84.100","A16.801","C78.000x003","D36.706","C34.001","E32.800x005","G47.300x034","I89.800x002","J16.800x001","J80.x00","T17.901","J67.200x002","I97.800x018","J18.801","J20.700","J67.800x002","J84.804","J94.801","J98.003","J95.900","J43.904","J86.000x013","A19.000x012","J95.810","D86.200","I26.900x003","A16.020","J40.x01","J98.800x014","J67.500","S27.301","J63.800x015","Q89.209","J63.800x024","A16.304","A15.806","J60.x01","A15.100x002","A16.017","J98.412","A16.200x012","J18.902","J94.800x003","J12.100","J63.800x020","A15.500x023","J86.000","D38.101","Q33.100","A16.037","A16.203","J81.x00x002","J86.008","R94.204","C34.101","B48.501+J17.2*","J43.900x001","A15.607","J63.800x018","A15.107","Q85.908","S27.313","R09.801","J15.800x001","D17.400x001","J20.400","A16.105","J63.800x003","R09.800x092","J39.804","J20.300","S27.800x013","J45.900x021","D48.700x019","J94.807","J12.300","E32.800x001","J46.x00x003","A15.005","J43.000x003","A16.804","A15.605","D38.100x002","J44.803","J46.x00x010","J92.901","J98.300","R06.600","J42.x00x003","R09.800x093","A19.000x019","S27.700","M35.002+J99.1*","A16.024","J18.000x001","J45.003","Q89.800x910","Q32.102","J15.602","A02.201+J17.0*","T27.600x001","D18.000x800","A16.003","J63.300x002","E85.404","J69.000x004","C34.100x004","J70.400","Q32.400x002","A15.810","Q32.400x005","R06.000","Q33.500","T17.803","A16.900x003","C39.800","J68.301","B39.000","R91.x04","T84.200x004","A16.400x005","A16.023","A15.505","J45.900x012","B39.000x001+J17.2*","J67.600x001","J82.x00x004","D38.200x001","J86.005","S27.710","A15.508","A15.509","J44.806","C34.800x003","J68.000x002","A16.302","R93.804","C78.201","A15.403","J39.805","A16.025","J39.801","C77.102","J93.800x001","J98.000x012","Q85.900x015","R06.000x003","T85.608","J10.001","J43.001","J84.110","D38.103","C49.300x001","E32.100","J63.800x011","J69.000x002","B42.000+J99.8*","R09.201","A15.000x003","B06.801+J17.1*","D17.400x004","A16.102","J84.800x003","A16.001","R04.802","Q34.100","J98.006","C34.901","J95.300","C34.900x006","J45.900","J43.900","I26.900x009","B06.800","D15.200x002","D38.300x001","I88.106","E32.002","A16.022","C33.x00","C34.803","J63.800x016","A06.500+J99.8*","J15.000x002","A16.103","J70.200","J94.201","A15.502","B66.401+J99.8*","J86.007","A15.106","A19.000x009","R06.800x005","D38.601","J45.007","J63.300x003","J21.900x002","J69.800x001","R05.x02","R94.202","A15.500x020","J22.x00","M33.103+J99.1*","J95.801","R06.200","J84.801","J82.x00x001","J63.400","S27.806","A15.500x024","A16.700x002","C38.400x003","J84.109","Q79.103","J63.800","S27.810","J45.900x031","A36.201","T86.803","S29.800","A15.305","C78.000","A15.803","J62.000x003","E32.801","C34.900x001","J63.800x012","A15.500x017","J93.003","C78.003","A16.012","J63.800x010","J84.900","A19.000x011","D15.700","A16.500x009","A15.302","A15.814","A15.500x015","A16.505","D21.302","A16.300x003","A43.000x001+J99.8*","D14.300x001","D18.105","C38.200","J45.900x001","A16.700x001","J62.802","T79.800x007","J67.000","A15.101","A37.900x004","J15.500","J84.800x008","C38.401","C34.000x002","J18.000x002","A19.000x002","J60.x00","A06.502+J17.3*","J18.002","A16.406","J67.200","M05.103+J99.0*","U07.100x002","C76.100","J98.800x001","C78.001","J90.x00","J43.902","J12.000","A15.807","C78.100","J20.500","A16.035","R05.x01","A15.103","R93.801","J43.000","J86.020","J98.800x006","A37.800x001","A15.812","A15.701","J69.100x001","B45.000","A16.004","J62.803","J98.413","J63.300x001","J98.417","S27.510","J62.000x002","J46.x00x006","T81.400x009","J43.200","A15.000x016","A19.000x001","J45.000","J84.105","J66.100","A15.503","A15.500x016","J20.901","J70.200x002","T85.700x804","R09.300","J84.101","J43.101","J40.x00x002","D38.201","J94.200","A15.402","J43.903","J15.700","A16.204","C34.800x001","J15.900","S27.310","A16.501","I89.800x021","J98.502","R84.500","J09.x01","A15.000x024","J41.800","A15.301","J86.014","J93.100x001","A16.301","D48.115","J68.101","J63.800x001","M33.201+J99.1*","J90.x01","A16.401","A16.403","J45.006","S28.000","S27.804","J84.104","J98.201","R09.000","J98.506","A15.703","J41.000","J47.x02","J67.900","Q33.800x002","R09.800x095","A15.500x004","A15.500x025","A16.305","J98.400x016","J96.900x002","Q85.904","J67.800x004","J84.103","A15.203","J46.x02","A15.100x010","A16.015","B25.000+J17.1*","Q32.300","D18.100x015","I89.800x017","J15.200","J98.011","J15.400","J62.000x001","D15.200","I88.900x002","Q33.002","J67.700x001","J60.x00x003","A16.013","C34.201","R06.802","A15.004","B40.200","B49.x14+J99.8*","D38.600x001","J18.000","A15.100x004","J98.401","M05.100+J99.0*","R84.800","J84.002","U07.100x003","R04.200","J86.009","A16.800x003","D17.400","A16.029","J46.x00x009","B39.100","A15.200x002","A15.500x001","A16.500x004","A15.802","C77.105","M05.102+J99.0*","J62.800x008","M35.904+J99.1*","C39.900x001","A15.407","A15.100x011","C34.300x003","J15.600x003","S25.401","J98.400x001","J98.400x013","J98.000x011","J44.900x004","A19.000x013","A15.601","J86.902","S27.501","J62.801","R06.804","J86.000x012","C79.800x809","R06.801","U04.900","R09.800x094","A15.000x022","Q33.400","J61.x00x002","R09.100x002","B37.100","S27.803","D48.709","B45.000x002+J99.8*","A15.500x013","S27.303","I26.900x010","A15.608","J45.903","D14.301","A15.406","I26.900x008","J09.x00","J95.800x010","S24.200","A15.813","S27.807","A15.405","J45.100x002","J98.600x001","J63.000x001","M33.901+J99.1*","A15.001","J98.504","R06.805","A16.500x001","M34.800x001+J99.1*","A15.000x026","M32.103+J99.1*","J21.100","S27.400","T27.200x001","A16.006","J15.601","D38.300x002","Q85.901","A19.000x004","S27.401","D18.000x814","B39.200","A15.500x012","J21.000","J62.800x004","A15.100x006","C34.900x005","A15.100x008","A15.606","J95.800x016"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCE入组条件，匹配规则：主诊断匹配");
        String result;

        result=EB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EB2.group(record);
        if (result.length()>0){
            return result;
        }

        result=EC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EC2.group(record);
        if (result.length()>0){
            return result;
        }

        result=ED1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EJ1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合EQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "EQY";
        }

        result=ER1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ER2.group(record);
        if (result.length()>0){
            return result;
        }

        result=ER3.group(record);
        if (result.length()>0){
            return result;
        }

        result=ES1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ES2.group(record);
        if (result.length()>0){
            return result;
        }

        result=ES3.group(record);
        if (result.length()>0){
            return result;
        }

        result=ET1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ET2.group(record);
        if (result.length()>0){
            return result;
        }

        result=EU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EW1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EX1.group(record);
        if (result.length()>0){
            return result;
        }

        result=EX2.group(record);
        if (result.length()>0){
            return result;
        }

        result=EZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCE的ADRG入组条件");
        return "";
    }
}

